#import('dart:html');

class AnimationRenderer {

  AnimationRenderer() {
  }

  void run() {
    write("Hello World!");
    write("Hello World!");
    WebSocket ws = new WebSocket("ws://192.168.1.13:8090/ws");
    
    print("WS Client started.");

    // After open, send a message to the server
    ws.on.open.add((event) {
      bool ret = ws.send("Hello There");
      print("Sent: $ret");
      ret = ws.send("I'm Amir's WS Client!");
      print("Sent: $ret");    
      ret = ws.send("What's your name?");
      print("Sent: $ret");    
    });

    // Handle messages from the server, printing to the console
    ws.on.message.add((event) {
      print("Got an event: $event");
      print("The data in the event is: " + event.data);
    });

    // Print message to the console on WS error
    ws.on.error.add((event) {
      print("whoa: $event");
    });
    
    ws.on.close.add((event) {
      print("closing now: $event");
    });
  }

  void write(String message) {
    // the HTML library defines a global "document" variable
    document.query('#status').innerHTML = message;
  }
}

void main() {
  new AnimationRenderer().run();
}
